home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / ifp1s157.zip / IFPCOMON.PAS next >
Pascal/Delphi Source File  |  1993-06-26  |  13KB  |  631 lines

  1. unit ifpcomon;
  2.  
  3. interface
  4.  
  5. uses Crt, Dos, ifpglobl, ifpextrn;
  6.  
  7. function getkey2: char2;
  8. function getnum: word;
  9. procedure caption1(a: string);
  10. procedure caption2(a: string);
  11. procedure caption3(a : string);
  12. function nocarry(regs: registers) : boolean;
  13. function hex(a : word; b : byte) : string;
  14. procedure unknown(a: string; b: word; c: byte);
  15. procedure yesorno(a : boolean);
  16. procedure yesorno2(a: boolean);
  17. procedure yesorno3(a: boolean);
  18. procedure dontknow;
  19. procedure dontknow2;
  20. procedure segofs(a, b : word);
  21. function showchar(a : char) : char;
  22. function power2(y: word): longint;
  23. procedure pause1;
  24. procedure pause2;
  25. procedure pause3(extra: integer);
  26. procedure pause4(direc: directions; var ch2: char2);
  27. procedure pause5(direc: directions; var ch2: char2);
  28. function bin4(a: byte) : string;
  29. procedure offoron(a: string; b: boolean);
  30. procedure zeropad(a: word);
  31. procedure zeropad3(a: word);
  32. procedure showvers;
  33. function cbw(a, b: byte) : word;
  34. function bin16(a: word) : string;
  35. procedure drvname(a: byte);
  36. procedure media(a, b: byte);
  37. procedure pagenameclr;
  38. procedure Intr(intno: byte; var regs: registers);
  39. procedure MsDos(var regs: registers);
  40. procedure TextColor(color: byte);
  41. procedure TextBackground(color: byte);
  42. function unBCD(b: byte): byte;
  43. function addzero(b: byte): string;
  44. procedure modeinfo(var vidmode, vidlen, vidpg: byte; var vidwid: word);
  45. procedure box;
  46. procedure center(s: string);
  47. function EMSOK: boolean;
  48.  
  49. implementation
  50.  
  51. uses ifpscrpt, ifphelp;
  52.  
  53. function getkey2: char2;
  54.   var
  55.     c: char;
  56.     c2: char2;
  57.  
  58.   begin
  59.   c:=ReadKey;
  60.   if c = #0 then
  61.     getkey2:=c + ReadKey
  62.   else
  63.     getkey2:=c;
  64.   end; {getkey2}
  65.  
  66. {^Make sure number entered, not any letters}
  67. function getnum: word;
  68.   var
  69.     inpchar: char;
  70.     number_string: string[2];
  71.     temp, position, code: word;
  72.     row, col: byte;
  73.     finish: boolean;
  74.  
  75.   begin
  76.   row:=WhereY;
  77.   col:=WhereX;
  78.   Write(' ':3);
  79.   GotoXY(col, row);
  80.   temp:=99;
  81.   finish:=false;
  82.   position:=0;
  83.   number_string:='';
  84.   TextColor(LightGray);
  85.   repeat
  86.     inpchar:=ReadKey;
  87.     case inpchar of
  88.       '0'..'9':if position < 2 then
  89.         begin
  90.         Inc(position);
  91.         Inc(number_string[0]);
  92.         number_string[position]:=inpchar;
  93.         Write(inpchar)
  94.         end;
  95.       #8: if position > 0 then
  96.         begin
  97.         Dec(position);
  98.         Dec(number_string[0]);
  99.         Write(^H' '^H)
  100.         end;
  101.       #27: if number_string = '' then
  102.           finish:=true
  103.         else
  104.           begin
  105.           number_string:='';
  106.           GotoXY(col, row);
  107.           ClrEol;
  108.           position:=0
  109.           end;
  110.       #13: finish:=true
  111.     end {case}
  112.   until finish;
  113.   if number_string <> '' then
  114.     Val(number_string, temp, code)
  115.   else
  116.     temp:=999;
  117.   getnum:=temp
  118.   end; {getnum}
  119.  
  120. procedure caption1(a: string);
  121.   begin
  122.   textcolor(LightGray);
  123.   Write(a);
  124.   textcolor(LightCyan)
  125.   end; {caption1}
  126.  
  127. procedure caption2(a: string);
  128.   const
  129.     capterm = ': ';
  130.  
  131.   var
  132.     i: byte;
  133.     xbool: boolean;
  134.  
  135.   begin
  136.   i:=length(a);
  137.   while (i > 0) and (a[i] = ' ') do
  138.     dec(i);
  139.   insert(capterm, a, i + 1);
  140.   caption1(a)
  141.   end; {caption2}
  142.  
  143. procedure caption3(a : string);
  144.   begin
  145.   caption2('  ' + a)
  146.   end; {caption3}
  147.  
  148. function nocarry(regs: registers) : boolean;
  149.   begin
  150.   nocarry:=regs.flags and fcarry = $0000
  151.   end; {nocarry}
  152.  
  153. function hex(a : word; b : byte) : string;
  154.   const
  155.     digit : array[$0..$F] of char = '0123456789ABCDEF';
  156.  
  157.   var
  158.     i : byte;
  159.     xstring : string;
  160.  
  161.   begin
  162.   xstring:='';
  163.   for i:=1 to b do
  164.     begin
  165.     insert(digit[a and $000F], xstring, 1);
  166.     a:=a shr 4
  167.     end;
  168.   hex:=xstring
  169.   end; {hex}
  170.  
  171. procedure unknown(a: string; b: word; c: byte);
  172.   begin
  173.   Writeln('(unknown', ' ', a, ' ', hex(b, c), ')')
  174.   end; {unknown}
  175.  
  176. procedure yesorno(a : boolean);
  177.   begin
  178.   if a then
  179.     Writeln('yes')
  180.   else
  181.     Writeln('no')
  182.   end; {yesorno}
  183.  
  184. procedure yesorno2(a: boolean);
  185.   begin
  186.   if a then
  187.     Write('yes')
  188.   else
  189.     Write('no')
  190.   end; {yesorno2}
  191.  
  192. procedure YesOrNo3(a: boolean);
  193.   begin
  194.   YesOrNo2(a);
  195.   if not a then
  196.     Write(' ');
  197.   end;
  198.  
  199. procedure dontknow;
  200.   begin
  201.   Writeln('(unknown)')
  202.   end; {dontknow}
  203.  
  204. procedure dontknow2;
  205.   begin
  206.   Write('(unknown)')
  207.   end; {dontknow2}
  208.  
  209. procedure segofs(a, b : word);
  210.   begin
  211.   Write(hex(a, 4), ':', hex(b, 4))
  212.   end; {segofs}
  213.  
  214. function showchar(a : char) : char;
  215.   begin
  216.   if a in pchar then
  217.     showchar:=a
  218.   else
  219.     showchar:='.'
  220.   end; {showchar}
  221.  
  222. function power2(y: word): longint;
  223.   begin
  224.   power2:=Trunc(exp((y * 1.0) * ln(2.0)))
  225.   end;
  226.  
  227. procedure pause1;
  228.   var
  229.     xbyte : byte;
  230.     xchar : char2;
  231.     SaveX, SaveY: byte;
  232.  
  233.   begin
  234.   xbyte:=TextAttr;
  235.   endit:=false;
  236.   TextColor(Cyan);
  237.   SaveX:=WhereX;
  238.   SaveY:=WhereY;
  239.   Write('( for more)');
  240.   if PrinterRec.Mode = 'A' then
  241.     ScreenPrint(Pg, PgNames[Pg], VerNum)
  242.   else
  243.     begin
  244.     repeat
  245.       xchar:=getkey2;
  246.       if xchar = #0#25 then
  247.         begin
  248.         ScreenPrint(Pg, PgNames[Pg], VerNum);
  249.         xchar:=#0#0
  250.         end;
  251.       if xchar = #0#$3B then
  252.         begin
  253.         HelpScreen(Pg, HelpVersion);
  254.         xchar:=#0#0
  255.         end;
  256.     until xchar <> #0#0;
  257.     if xchar <> #0#80 then
  258.       begin
  259.       endit:=true;
  260.       c2:=xchar
  261.       end;
  262.     end;
  263.   TextAttr:=xbyte;
  264.   GotoXY(SaveX, SaveY);
  265.   Write('            ')
  266.   end; {pause1}
  267.  
  268. procedure pause2;
  269.   var
  270.     xbyte : byte;
  271.  
  272.   begin
  273.   if WhereY + hi(WindMin) > hi(WindMax) then
  274.     begin
  275.     xbyte:=TextAttr;
  276.     TextColor(Cyan);
  277.     pause1;
  278.     if not endit then
  279.       begin
  280.       Clrscr;
  281.       Writeln('(continued)');
  282.       end;
  283.     TextAttr:=xbyte
  284.     end
  285.   end; {pause2}
  286.  
  287. procedure pause3(extra: integer);
  288.   var
  289.     xbyte: byte;
  290.   begin
  291.   endit:=false;
  292.   if WhereY + Hi(WindMin) + Abs(extra) > Hi(WindMax) then
  293.     begin
  294.     xbyte:=TextAttr;
  295.     TextColor(Cyan);
  296.     pause1;
  297.     if not endit then
  298.       begin
  299.       ClrScr;
  300.       if extra < 0 then
  301.         Writeln('(continued)');
  302.       end;
  303.     TextAttr:=xbyte
  304.     end
  305.   end; {pause3}
  306.  
  307. procedure pause4(Direc: Directions; var ch2: char2);
  308.   var
  309.     xbyte : byte;
  310.     xchar : char2;
  311.     SaveX, SaveY: byte;
  312.  
  313.   begin
  314.   xbyte:=TextAttr;
  315.   endit:=false;
  316.   TextColor(Cyan);
  317.   SaveX:=WhereX;
  318.   SaveY:=WhereY;
  319.   case Direc of
  320.     none:   Write('(any key)');
  321.     up:     Write('( for more)');
  322.     down:   Write('( for more)');
  323.     updown: Write('( or  for more)')
  324.   end;
  325.   repeat
  326.     if PrinterRec.Mode = 'A' then
  327.       if Direc = up then
  328.         xchar:=#0#81
  329.       else
  330.         begin
  331.         ScreenPrint(Pg, PgNames[Pg], VerNum);
  332.         xchar:=#0#80;
  333.         end
  334.     else
  335.       begin
  336.       xchar:=getkey2;
  337.       if xchar = #0#25 then
  338.         begin
  339.         ScreenPrint(Pg, Pgnames[Pg], VerNum);
  340.         xchar:=#0#0
  341.         end
  342.       end;
  343.   until xchar <> #0#0;
  344.   if (xchar[1] <> #0) or
  345.     ((xchar[1] = #0) and (not (xchar[2] in [#80, #72]))) then
  346.     begin
  347.     endit:=true;
  348.     c2:=xchar;
  349.     end;
  350.   TextAttr:=xbyte;
  351.   GotoXY(SaveX, SaveY);
  352.   Write('                 ');
  353.   ch2:=xchar;
  354.   end; {pause4}
  355.  
  356. procedure pause5(direc: directions; var ch2: char2);
  357.   var
  358.     xbyte : byte;
  359.  
  360.   begin
  361.   ch2:=#0#0;
  362.   if WhereY + Hi(WindMin) > Hi(WindMax) then
  363.     begin
  364.     xbyte:=TextAttr;
  365.     TextColor(Cyan);
  366.     Pause4(direc, ch2);
  367.     if not endit then
  368.       Clrscr;
  369.     TextAttr:=xbyte
  370.     end
  371.   end; {pause5}
  372.  
  373. function bin4(a : byte) : string;
  374.   const
  375.     digit : array[0..1] of char = '01';
  376.  
  377.   var
  378.     xstring : string;
  379.     i : byte;
  380.  
  381.   begin
  382.   xstring:='';
  383.   for i:=3 downto 0 do
  384.     begin
  385.     insert(digit[a mod 2], xstring, 1);
  386.     a:=a shr 1
  387.     end;
  388.   bin4:=xstring
  389.   end; {bin4}
  390.  
  391. procedure offoron(a : string; b : boolean);
  392.   begin
  393.   caption3(a);
  394.   if b then
  395.     Write('on')
  396.   else
  397.     Write('off')
  398.   end; {offoron}
  399.  
  400. procedure zeropad(a : word);
  401.   begin
  402.   if a < 10 then
  403.     Write('0');
  404.   Write(a)
  405.   end; {zeropad}
  406.  
  407.  procedure zeropad3(a: word);
  408.    begin
  409.    if a < 10 then
  410.      Write('00')
  411.    else
  412.      if a < 100 then
  413.        Write('0');
  414.    Write(a)
  415.    end; {zeropad3}
  416.  
  417. procedure showvers;
  418.   begin
  419.   if osmajor > 0 then
  420.     Writeln(osmajor, decimal, addzero(osminor))
  421.   else
  422.     Writeln('1', decimal, 'x')
  423.   end; {showvers}
  424.  
  425. function cbw(a, b : byte) : word;
  426.   begin
  427.   cbw:=word(b) shl 8 + a
  428.   end; {cbw}
  429.  
  430. function bin16(a : word) : string;
  431.   function bin8(a : byte) : string;
  432.     begin
  433.     bin8:=bin4(a shr 4) + '_' + bin4(a and $0F)
  434.     end; {bin8}
  435.  
  436.   begin {bin16}
  437.   bin16:=bin8(hi(a)) + '_' + bin8(lo(a))
  438.   end; {bin16}
  439.  
  440. procedure drvname(a : byte);
  441.   begin
  442.   Write(chr(ord('A') + a), ': ')
  443.   end; {drvname}
  444.  
  445. procedure media(a, b : byte);
  446.   procedure diskette(a, b, c : byte);
  447.     begin
  448.     Writeln('floppy ', a, ' side, ', b, ' sctr, ', c, ' trk')
  449.     end; {diskette}
  450.  
  451.   begin {media}
  452.   caption3('Media');
  453.   case a of
  454.     $FF : diskette(2, 8, 40);
  455.     $FE : diskette(1, 8, 40);
  456.     $FD : diskette(2, 9, 40);
  457.     $FC : diskette(1, 9, 40);
  458.     $F9 : if b = 1 then
  459.       diskette(2, 15, 80)
  460.     else
  461.       diskette(2, 9, 80);
  462.     $F8 : Writeln('fixed disk');
  463.     $F0 : diskette(2, 18, 80)
  464.     else
  465.       unknown('media', a, 2)
  466.   end
  467.   end; {media}
  468.  
  469. procedure pagenameclr;
  470.   var
  471.     xbyte: byte;
  472.  
  473.   begin
  474.   xbyte:=TextAttr;
  475.   Window(x1, tlength, x2 - 1, tlength);
  476.   TextColor((TextAttr and $70) shr 4);
  477.   ClrScr;
  478.   TextAttr:=xbyte;
  479.   Window(1, 1, twidth, tlength)
  480.   end; {pagenameclr}
  481.  
  482. procedure Intr(intno: byte; var regs: registers);
  483.   begin
  484.   AltIntr(intno, regs)
  485.   end;
  486.  
  487. procedure MsDos(var regs: registers);
  488.   begin
  489.   AltMsDos(regs)
  490.   end;
  491.  
  492. {These first two procedures filter the color commands to allow Black&White}
  493. procedure TextColor(color: byte);
  494.   var
  495.     temp: byte;
  496.   begin
  497.   if mono then
  498.     begin
  499.     case (color and $0F) of
  500.       0: temp:=0;
  501.       1..7: temp:=7;
  502.       8..15: temp:=15
  503.       end;
  504.     if color > 15 then
  505.       temp:=temp + Blink;
  506.     end
  507.   else
  508.     temp:=color;
  509.   Crt.TextColor(temp)
  510.   end; {TextColor}
  511.  
  512. procedure TextBackground(color: byte);
  513.   var
  514.     temp: byte;
  515.   begin
  516.   temp:=color;
  517.   if mono and (color < 7) then
  518.     temp:=0;
  519.   Crt.TextBackground(temp);
  520.   end; {TextBackground}
  521.  
  522. function unBCD(b: byte): byte;
  523.   begin
  524.   unBCD:=(b and $0F) + ((b shr 4) * 10)
  525.   end; {unBCD}
  526.  
  527. function addzero(b: byte): string;
  528.   var
  529.     c2: string[2];
  530.   begin
  531.   Str(b:0, c2);
  532.   if b < 10 then
  533.     c2:='0' + c2;
  534.   addzero:=c2
  535.   end; {addzero}
  536.  
  537. procedure modeinfo(var vidmode, vidlen, vidpg: byte; var vidwid: word);
  538.   var
  539.     regs: registers;
  540.  
  541.   begin
  542.   with regs do
  543.     begin
  544.     AH:=$0F;
  545.     Intr($10, regs);
  546.     vidmode:=AL;
  547.     vidwid:=AH;
  548.     vidpg:=BH;
  549.     AX:=$1200;
  550.     BL:=$10;
  551.     Intr($10, regs);
  552.     if BL = $10 then
  553.       vidlen:=25
  554.     else
  555.       vidlen:=Mem[$40:$84] + 1;
  556.     end
  557.   end; {modeinfo}
  558.  
  559. procedure box;
  560.   const
  561.     frame: array[1..8] of char = '╔═╗║║╚═╝';
  562.   var
  563.     h, w, x, y: word;
  564.  
  565.   begin
  566.   w:=Lo(WindMax) - Lo(WindMin) + 1;
  567.   h:=Hi(WindMax) - Hi(WindMin) + 1;
  568.   Inc(WindMax, $0101);
  569.   GotoXY(1, 1);
  570.   Write(frame[1]);
  571.   for x:=2 to w - 1 do
  572.     Write(frame[2]);
  573.   GotoXY(w, 1);
  574.   Write(frame[3]);
  575.   for y:=2 to h - 1 do
  576.     begin
  577.     GotoXY(1, y);
  578.     Write(frame[4]);
  579.     GotoXY(w, y);
  580.     Write(frame[5]);
  581.     end;
  582.   GotoXY(1, h);
  583.   Write(frame[6]);
  584.   GotoXY(2, h);
  585.   for x:=2 to w-1 do
  586.     Write(frame[7]);
  587.   GotoXY(w, h);
  588.   Write(frame[8]);
  589.   Dec(WindMax, $0202);
  590.   Inc(WindMin, $0101);
  591.   end;
  592.  
  593. procedure center(s: string);
  594.   var
  595.     x, halfwidth, halfstr: integer;
  596.  
  597.   begin
  598.   halfwidth:=(Lo(WindMax) - Lo(WindMin)) div 2;
  599.   halfstr:=Length(s) div 2;
  600.   if (halfwidth - halfstr) > 0 then
  601.     for x:=1 to (halfwidth - halfstr) do
  602.       Write(' ');
  603.   Write(s);
  604.   end;
  605.  
  606. function EMSOK: boolean;
  607.   var
  608.     S: string;
  609.     EMSSeg, Address: word;
  610.     Regs: Registers;
  611.  
  612.   begin
  613.   EMSOK:=false;
  614.   if longint(IntVec[$67]) <> 0 then
  615.     begin
  616.     EMSSeg:=longint(IntVec[$67]) shr 16;
  617.     S:='';
  618.     for Address:=$A to $11 do
  619.       S:=S + Chr(Mem[EMSSeg:Address]);
  620.     if S = 'EMMXXXX0' then
  621.       with Regs do
  622.         begin
  623.         AH:=$40;
  624.         Intr($67, regs);
  625.         if AH = 0 then
  626.           EMSOK:=true;
  627.         end;
  628.     end;
  629.   end;
  630.  
  631. end.